<?php

namespace app\admin\controller;

use think\Controller;
use app\common\lib\IAuth;

class Admin extends Base
{
    public function add()
    {
        if (request()->isPost()) {
            $data = input('post.');
            $validate = validate('AdminUser');
            if ($validate->check($data)) {
                $data['password'] = IAuth::setPassword($data['password']);
                $data['create_time'] = time();
                try {
                    $id = model('AdminUser')->add($data);
                } catch (\Exception $e) {
                    $this->error($e->getMessage());
                }
                if ($id) {
                    $this->success('新增数据成功!');
                } else {
                    $this->error('error');
                }
            } else {
                $this->error($validate->getError());
            }
        } else {
            return $this->fetch();
        }
    }
}
